//
//  LLDashesLineView.m
//  lrlzapp
//
//  Created by dl on 16/3/2.
//  Copyright © 2016年 lrlz. All rights reserved.
//

#import "LLDashesLineView.h"

@implementation LLDashesLineView

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (void)drawRect:(CGRect)rect {
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextBeginPath(context);
    CGContextSetLineWidth(context, SUIT_LINE_WIDTH * 2);                                     // 线宽度
    CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor);
    CGFloat lengths[] = {4, 4};                                             // 先绘制4个点，跳过4个点，如此反复
    CGContextSetLineDash(context, 0, lengths, 2);                            // 注意2(count)的值等于lengths数组的长度; 0是刚开始跳过几个点
    CGContextMoveToPoint(context, self.startPoint.x, self.startPoint.y);
    if (self.endPoint.x == 0 && self.endPoint.y == 0) {
        CGContextAddLineToPoint(context, self.frame.size.width, 0);
    } else {
        CGContextAddLineToPoint(context, self.endPoint.x, self.endPoint.y);
    }
    CGContextStrokePath(context);
}
@end
